<template>
  <div>
    <van-nav-bar
      title="个人资料"
      left-arrow
      @click-left="onClickLeft"
    />

    <!-- 基本信息 -->
    <van-cell-group>
      <van-field
        v-model="message.nickName"
        label="昵称"
        placeholder="请输入昵称"
      />
      <van-field
        v-model="message.sex"
        label="性别"
        placeholder="请输入性别"
      />
      <van-field
        v-model="message.birthday"
        label="生日"
        placeholder="请输入生日"
      />
      <van-field
        v-model="message.addr"
        label="地区"
        placeholder="所属地区"
      />
      <van-field
        v-model="message.card"
        label="身份"
        placeholder="身份信息"
      />
    </van-cell-group>
    <van-button @click='save' type="info" size="large">保存信息</van-button>
  </div>
</template>

<script>
  import * as get from '@/yoona/getProList.js';
  import * as post from '@/api/postProList.js';
  export default {
    name:'Mine',
    data(){
      return {
        message:{},
        username:''
      }
    },
    methods:{
      onClickLeft(){
        this.$router.back(-1)
      },
      save(){
        this.message.username = this.username
        let msg = this.message;
         get.setUserMsg({
           username:msg.username,
           nickName:msg.nickName,
           sex:msg.sex,
           birthday:msg.birthday,
           addr:msg.addr,
           card:msg.card
         }).then(res=>{
           if(res.data.code == 1){
            this.$toast('修改成功');
             this.$router.push('/mine');
           }
         })
      }
    },
    mounted(){
      let obj = {
        nickName:'',
        sex:'',
        birthday:'',
        addr:'',
        card:''
      }
      this.username = this.$store.state.message.username;
      if(this.username != ''){
        get.getUserMsg({
          username:this.username
        }).then(res=>{
          if(res.data.code == 1 && res.data.data.length>0){
            this.message = res.data.data[0];
          }else{
            this.message = obj;
          }
        })
      }else{
        this.message = obj;
      }
    },
    watch:{

    }
  }
</script>

<style>
</style>
